<?php


namespace app\service\controller;

use think\worker\Server;

class Worker extends Server
{
    protected $socket = 'text://0.0.0.0:1111';
    protected $option = [
        'name' => 'zb_chat',
        'count' => 2
    ];

    // onWorkerStart
    function onWorkerStart ($worker) {
        $mqtt = new \Workerman\Mqtt\Client('mqtt://47.99.158.37:1883');
        $mqtt->onConnect = function($mqtt) {
            $mqtt->subscribe('test');
        };
        $mqtt->onMessage = function($topic, $content){
            var_dump($topic, $content);
        };
        $mqtt->connect();
        echo 'worker start';
    }
    // onWorkerReload
    function onWorkerReload($worker) {

    }
    // onConnect
    function onConnect($connection) {

    }
    // onMessage
    function onMessage($connection, $data) {
        $connection->send('receive success:'.$data);
    }
    // onClose
    function onClose($connection) {

    }
    // onError
    function onError($connection, $code, $msg) {
        echo "error [ $code ] $msg\n";
    }


}